﻿
Partial Class WebForm_ManageRoleUserMappingByUser_ucQueryUser
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.BindDDLOrganizationID()
            Me.BindGV()
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub
    Protected Sub lbtnSetup_Click(ByVal sender As Object, ByVal e As EventArgs)
        TGridView1.EditIndex = -1
        OpenManageUserRoleMapping1.EmployeeID = TGridView1.DataKeys(DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow).RowIndex).Value.ToString()
        OpenManageUserRoleMapping1.InitDataAndShow()
    End Sub


    Protected Sub TGridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles TGridView1.PageIndexChanging
        TGridView1.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    Protected Sub TGridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles TGridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If DirectCast(e.Row.FindControl("lblActive0"), Label).Text = "Y" Then
                DirectCast(e.Row.FindControl("chkActive0"), CheckBox).Checked = True
            End If
        End If
    End Sub

    Protected Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0
        sql.AppendFormat(" select A.*,B.OrganizationName from Employee A inner join Organization B ")
        sql.AppendFormat(" on A.OrganizationID = B.OrganizationID Where 1=1 ")

        If txtEmployeeID.Text <> "" Then
            sql.AppendFormat(" And A.EmployeeID Like '%{0}%' ", txtEmployeeID.Text)
        End If

        If txtEmployeeName.Text <> "" Then

            sql.AppendFormat(" And A.EmployeeName Like '%{0}%' ", txtEmployeeName.Text)
        End If
        If ddlOrganizationID.SelectedValue <> "" Then
            sql.AppendFormat(" And A.OrganizationID = '{0}' ", ddlOrganizationID.SelectedValue)
        ElseIf ddlOrganizationID.SelectedValue = "0" Then

        End If

        TGridView1.DataSource = dat.GetData(sql)
        TGridView1.DataBind()
    End Sub

    Private Sub BindDDLOrganizationID()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select o.* ")
        sql.AppendFormat("from Organization o ")
        'sql.AppendFormat("inner join UserOrganizationAuth oa on o.OrganizationID = oa.OrganizationID ")
        sql.AppendFormat("where o.Active = 'Y' ")
        'sql.AppendFormat("and oa.UserID = '{0}' ", clsAuth.GetUserID())

        Me.ddlOrganizationID.DataTextField = "OrganizationName"
        Me.ddlOrganizationID.DataValueField = "OrganizationID"
        Me.ddlOrganizationID.DataSource = dat.GetData(sql)
        Me.ddlOrganizationID.DataBind()

        Me.ddlOrganizationID.Items.Insert(0, MyObj.GetDDLSelectAllItem())
    End Sub

    Protected Function BooleanConverter(ByVal strTMP As Object) As Boolean
        Return (IIf(strTMP.ToString() = "Y", True, False))
    End Function

    Public ReadOnly Property SelectedID() As String
        Get
            Return "0"
        End Get
    End Property


End Class
